package com.ma4567.remotecontroller.MysqlHelper;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class ConnectPool {
    public static ComboPooledDataSource DataSource;
    public static void createDataSource() {
        DataSource = new ComboPooledDataSource();
        DataSource.setJdbcUrl("jdbc:mysql://localhost:3306/jdbc?verifyServerCertificate=false&useSSL=false&serverTimezone=Asia/Shanghai");
        DataSource.setUser("root");
        DataSource.setPassword("123456");
    }

    public static Connection getConnection() throws SQLException {
        if(DataSource == null) {
            createDataSource();
        }

        return DataSource.getConnection();
    }
}
